﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using tms.Menu_Roles.Dto;
using Microsoft.AspNetCore.Mvc;

namespace tms.Menu_Roles
{
    //[ApiExplorerSettings(GroupName = "v1")]
    public class Menu_RoleService : CrudAppService<Menu_Role, Menu_RoleDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateMenu_RoleDto>, IMenu_RoleService
    {
        private readonly IRepository<Menu, Guid> repo_Menu;
        private readonly IRepository<Role, Guid> repo_Role;
        private readonly IRepository<Menu_Role, Guid> repository;

        public Menu_RoleService(
            IRepository<Menu, Guid> repo_menu,
            IRepository<Role, Guid> repo_role,
            IRepository<Menu_Role, Guid> repository
            ) : base(repository)
        {
            repo_Menu = repo_menu;
            repo_Role = repo_role;
            this.repository = repository;
        }

        /// <summary>
        /// 更新中间表
        /// </summary>
        /// <returns></returns>
        [HttpGet("/UpdateMany")]
        public async Task UpdateMany()
        {
            var roleId = (await repo_Role.FirstOrDefaultAsync()).Id;
            await repository.InsertManyAsync((await repo_Menu.GetListAsync()).Select(m => new Menu_Role {
                MenuId = m.Id,
                RoleId = roleId
            }));
        }
    }
}